package com.weimob.mcloud.wechatwork.customer.service.user.base;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.weimob.mcloud.wechatwork.common.support.codec.serializer.LongSerializer;

import java.io.Serializable;
import java.util.List;

/**
 * 结果分页包装类
 * Create Time: 2021年10月20日 17:24
 *
 * @author maosheng.li
 **/
public class PageResponse<T> implements Serializable {

    private static final long serialVersionUID = -6417831885059153499L;
    /**
     * 数据内容
     */
    private List<T> results;

    /**
     * 页码
     */
    private Integer pageNum;

    /**
     * 分页大小
     */
    private Integer pageSize;

    /**
     * 总数量
     */
    @JsonSerialize(using = LongSerializer.class)
    private Long totalCount;
    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 滚动游标
     */
    private String cursor;

    public PageResponse() {
    }

    public PageResponse(List<T> data) {
        this.results = data;
    }

    public PageResponse(List<T> data, Integer pageNum, Integer pageSize, Long totalCount) {
        this.results = data;
        this.totalCount = totalCount;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.intiTotalPage();
    }

    public void intiTotalPage() {
        if (null != this.pageNum || null != this.pageSize) {
            this.totalPage = this.pageSize > 0 && this.totalCount.intValue() > 0 ? (this.totalCount.intValue() + this.pageSize - 1) / this.pageSize : 0;
        }
    }


    public List<T> getResults() {
        return results;
    }

    public void setResults(List<T> results) {
        this.results = results;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getCursor() {
        return cursor;
    }

    public void setCursor(String cursor) {
        this.cursor = cursor;
    }
}
